# 16. 游戏分组

16

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let res = Infinity;
let totalSum = 0;
let targetSum = 0;
function dfs (nums, idx, count ,currentSum) {
    if (count === 5) {
        let otherTeamSum = totalSum - currentSum;
        res = Math.min(res, Math.abs(currentSum - otherTeamSum))
        return;
    }

    if (idx === 10) return;
    dfs(nums, idx +1, count+1, currentSum + nums[idx]);
    dfs(nums, idx + 1, count, currentSum);
}


rl.on('line', (line) => {
    let nums = input.split(' ').map(Number);
    for(let num of nums) {
        totalSum += num;
    }
    targetSum = totalSum / 2;
    dfs(nums, 0, 0, 0);
    console.log(res);
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31